<?php
	header("Content-Type: text/html;charset=utf-8");
	include("function/_nosql.php"); //
	include("function/function.php");
	include("_include.user.judge.php");
	$kboy_user = $_SESSION['kboy_user'];
	$kboy_userid = $_SESSION['kboy_userid'];
	
	$action = chkstr(trim($_REQUEST['action']));
	$user_pid = chkstr(trim($_REQUEST['user_pid']));
	$user_phone = chkstr(trim($_REQUEST['user_phone']));
	if($action == "add"){
		// 手机号验证
		if(!isMobile($user_phone)){
			echo erro("手机号格式错误！");
		}
		$user_style = getClassName("kboy_user","user_style","uid='$user_pid'");
		if($user_style != 1){
			echo erro("推介人必须为CVA会员！");
		}
		$is_reguser = getNewsNums("kboy_user","user_phone='$user_phone' and uid='$user_pid'");
		if($is_reguser == 0){
			$is_reguser = getNewsNums("kboy_user","user_tel='$user_phone' and uid='$user_pid'");
		}
		
		if($is_reguser == 1){
			// 修改数据
			$mysql = new sqlstr("kboy_user"); 
			$mysql -> set("user_pid",$user_pid);
			$news_sql = $mysql -> updateSql("uid=".$_SESSION['kboy_userid']);
			$news_res = mysql_query($news_sql);
			if($news_res){
			echo ok("操作成功","user_index.php");
			}else{
				echo erro("服务器内部错误");
			}
		}else{
			echo erro("请正确填写推荐人手机号或ID");
		}
	}else{
		echo erro("参数错误");
	}
?>